﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HZ.Supervise.Web.Secondphase.ReportHospital
{
    public partial class HospitalMedicalList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Databing();
                cblMonth.Visible = false;
            }
        }
        public void Databing()
        {
            //<asp:BoundField DataField="GoodsInfo" HeaderText="流水号" ReadOnly="true" />
            //    <asp:BoundField DataField="ProductName" HeaderText="通用名称" ReadOnly="true" />
            //    <asp:BoundField DataField="MedicineModelName" HeaderText="剂型" ReadOnly="true" />
            //    <asp:BoundField DataField="Outlookc" HeaderText="规格" ReadOnly="true" />
            //    <asp:BoundField DataField="Unit" HeaderText="单位" ReadOnly="true" />
            //    <asp:BoundField DataField="Factor" HeaderText="系数" ReadOnly="true" />
            //    <asp:BoundField DataField="ProcurePrice" HeaderText="采购限价" ReadOnly="true" />
            //    <asp:BoundField DataField="CompanyName_Sc" HeaderText="生产企业" ReadOnly="true" />
            //    <asp:BoundField DataField="PurchaseNumerbTotalc" HeaderText="采购总数量" ReadOnly="true" />
            //    <asp:BoundField DataField="PurchaseAmountTotal" HeaderText="采购总金额" ReadOnly="true" />
            //    <asp:BoundField DataField="LastMonthRanked" HeaderText="上月排名" ReadOnly="true" />
            //    <asp:BoundField DataField="RankedChange" HeaderText="名次变化" ReadOnly="true" />
            DataTable dt = new DataTable();
            DataColumn dc1 = new DataColumn("hospital", typeof(string)); dt.Columns.Add(dc1);
            //DataColumn dc2 = new DataColumn("PurchaseNumerbTotalc", typeof(string)); dt.Columns.Add(dc2);
            DataColumn dc2 = new DataColumn("PurchaseNumerbTotalc_jb", typeof(string)); dt.Columns.Add(dc2);
            DataColumn dc3 = new DataColumn("PurchaseNumerbTotalc_fjb", typeof(string)); dt.Columns.Add(dc3);
           // DataColumn dc5 = new DataColumn("PurchaseAmountTotal", typeof(string)); dt.Columns.Add(dc5);
            DataColumn dc4 = new DataColumn("PurchaseAmountTotal_jb", typeof(string)); dt.Columns.Add(dc4);
            DataColumn dc5 = new DataColumn("PurchaseAmountTotal_fjb", typeof(string)); dt.Columns.Add(dc5);
            //DataColumn dc8 = new DataColumn("LastMonthRanked", typeof(string)); dt.Columns.Add(dc8);
           // DataColumn dc9 = new DataColumn("RankedChange", typeof(string)); dt.Columns.Add(dc9);

            DataColumn dc6 = new DataColumn("PurchaseNumerbTotalc_jb1", typeof(string)); dt.Columns.Add(dc6);
            DataColumn dc7= new DataColumn("PurchaseNumerbTotalc_fjb1", typeof(string)); dt.Columns.Add(dc7);
            // DataColumn dc5 = new DataColumn("PurchaseAmountTotal", typeof(string)); dt.Columns.Add(dc5);
            DataColumn dc8 = new DataColumn("PurchaseAmountTotal_jb2", typeof(string)); dt.Columns.Add(dc8);
            DataColumn dc9 = new DataColumn("PurchaseAmountTotal_fjb2", typeof(string)); dt.Columns.Add(dc9);
            for (int i = 0; i < 10; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = "昆明地市" + i.ToString();
                dr[1] = "1000";
                dr[2] = "300";
                dr[3] = "600";
                dr[4] = "90000.000";
                dr[5] = "20000.000";
                dr[6] = "70000.00";
                dr[7] = "60000.00";
                dr[8] = "40000.00";
                dt.Rows.Add(dr);
            }
            
            gvwProcureCatalog.DataSource = dt;
            gvwProcureCatalog.DataBind();
        }

        /// <summary>
        /// 变换列头
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwProcureCatalog_RowCreated(object sender, GridViewRowEventArgs e)
        {
            int n = 0;
            switch (e.Row.RowType)
            {
                case DataControlRowType.Header:

                    
                     //没有选择的情况
                    if (string.IsNullOrEmpty(txtMonth.Text.ToString().Trim()))
                    {
                        //没有选择月份，显示空表头
                        return;
                    } 
                    else
                    {
                        string[] month=txtMonth.Text.Substring(0, txtMonth.Text.Length - 1).Split('|');
                        //第一行
                        TableCellCollection tcHeader = e.Row.Cells;
                        tcHeader.Clear();
                        tcHeader.Add(new TableHeaderCell());
                        tcHeader[n].Attributes.Add("colspan", "1"); //跨Row
                        tcHeader[n].Attributes.Add("bgcolor", "LightSteelBlue");
                        tcHeader[n].Text = "";
                        n++;
                        for (int i = 0; i < month.Length;i++ )
                        {
                            tcHeader.Add(new TableHeaderCell());
                            tcHeader[n].Attributes.Add("colspan", "4"); //跨Column
                            tcHeader[n].Text = month[i].ToString();
                            n++;
                        }
                        tcHeader.Add(new TableHeaderCell());
                        tcHeader[n].Attributes.Add("colspan", "2"); //跨Column
                        tcHeader[n].Text = "</th></tr><tr>";
                        n++;

                        //第二行
                        tcHeader.Add(new TableHeaderCell());
                        tcHeader[n].Attributes.Add("bgcolor", "LightSteelBlue");
                        tcHeader[n].Text = "";
                        n++;
                        for (int j = 0; j < (month.Length);j++ )
                        {
                            tcHeader.Add(new TableHeaderCell());
                            tcHeader[n].Attributes.Add("bgcolor", "LightSteelBlue");
                            tcHeader[n].Attributes.Add("colspan", "2");
                            tcHeader[n].Text = "采购总金额【11111】";
                            n++;
                            tcHeader.Add(new TableHeaderCell());
                            tcHeader[n].Attributes.Add("bgcolor", "LightSteelBlue");
                            tcHeader[n].Attributes.Add("colspan", "2");
                            tcHeader[n].Text = "配送总金额【111111】";
                            n++;
                        }
                        tcHeader.Add(new TableHeaderCell());
                        tcHeader[n].Attributes.Add("bgcolor", "LightSteelBlue");
                        tcHeader[n].Attributes.Add("colspan", "2");
                        tcHeader[n].Text = "</th></tr><tr>";
                        n++;

                        //第三行表头
                        tcHeader.Add(new TableHeaderCell());
                        tcHeader[n].Attributes.Add("bgcolor", "Khaki");
                        tcHeader[n].Text = "医院";
                        n++;
                        for (int k = 0; k < (month.Length * 2);k++ )
                        {
                            tcHeader.Add(new TableHeaderCell());
                            tcHeader[n].Attributes.Add("bgcolor", "Khaki");
                            tcHeader[n].Text = "基药总金额";
                            n++;
                            tcHeader.Add(new TableHeaderCell());
                            tcHeader[n].Attributes.Add("bgcolor", "Khaki");
                            tcHeader[n].Text = "非基药总金额";
                            n++;
                        }
                        tcHeader.Add(new TableHeaderCell());
                        tcHeader[n].Attributes.Add("bgcolor", "Khaki");
                        tcHeader[n].Text = "操作";
                        n++;
                        tcHeader.Add(new TableHeaderCell());
                        tcHeader[n].Attributes.Add("bgcolor", "Khaki");
                        tcHeader[n].Text = "图表</th></tr><tr>";
                        break;
                    }
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            Databing();
        }

        protected void lbnSwitch_Click(object sender, EventArgs e)
        {

        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {

        }

        protected void lbtnSee_Click(object sender, EventArgs e)
        {

        }

        protected void btnMonthClick(object sender, EventArgs e)
        {
            cblMonth.ClearSelection();
            cblMonth.Visible = true;
            txtMonth.Text = "";
        }

        //protected void cblMonth_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    int i = ((CheckBoxList)sender).SelectedIndex;
        //    if (cblMonth.Items. == true)
        //    {
        //        txtMonth.Text += cblMonth.SelectedItem.Text + "|";
        //    }
        //    else
        //    {
        //        txtMonth.Text.Replace(cblMonth.SelectedItem.Text+"|", "");
        //    }
        //}

        protected void btnCancelMonth_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < cblMonth.Items.Count;i++ )
            {
                if(cblMonth.Items[i].Selected==true)
                {
                    txtMonth.Text += cblMonth.Items[i].Text + "|";
                }
            }
            cblMonth.ClearSelection();
            cblMonth.Visible = false;
        }

      
    }
}
